import HYRequest from "./request";
import { ElMessage } from "element-plus";
// let BASE_URL = ''
const TIME_OUT = 10000; //默认超时时间
const hyRequest = new HYRequest({
  // baseURL:BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      config.headers.userId = localStorage.getItem("USER_ID") || ''; // 添加用户id
      return config;
    },
    requestInterceptorCatch: (err) => {
      return err;
    },
    responseInterceptor: (res) => {
      const resData = res.data;
      if (resData.code != 1) {
        ElMessage.error(resData.msg);
        return Promise.reject(res.data);
      }
      return res;
    },
    responseInterceptorCatch: (err) => {
      return err;
    },
  },
});
export default hyRequest;
